<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;

use Illuminate\Database\Eloquent\Model;

class Firm extends Model
{
    use HasDateTimeFormatter;


    protected $fillable = [
        'user_id',
        'profession_id',
        'category_id',
        'name',
        'area',
        'corporate_name',
        'idcard_reverse_photo',
        'idcard_front_photo',
        'business_license',
        'corporate_phone',
        'consult_time',
        'is_cooperation',
        'cooperation_desc',
        'reject_reason',
        'audit_status',
        'is_warn'
    ];

    protected $attributes = [
        'audit_status' => 1,
        'cooperation_desc' => ''
    ];

    protected $casts = [
        'cooperation_desc' => 'string'
    ];


    public function profession()
    {
        return $this->belongsTo(FirmProfession::class, 'profession_id');
    }

    public function category()
    {
        return $this->belongsTo(FirmCategory::class, 'category_id');
    }

    public function user()
    {
        return $this->belongsTo(User::class, 'user_id');
    }

    public function brands()
    {
        return $this->hasMany(FirmBrand::class, 'firm_id');
    }

    public function follow()
    {
        return $this->belongsTo(UserFollow::class, 'user_id', 'friend_id');
    }

    public function profile()
    {
        return $this->hasOne(FirmProfile::class, 'firm_id');
    }


    public function interested()
    {
        return $this->hasMany(FirmNotInterested::class, 'firm_id');
    }

    public function gift()
    {
        return $this->morphMany(Gift::class, 'giftable');
    }


}
